using System;
using System.Collections.Generic;
using System.Text;

namespace FastSpring.Base
{
    public class SQLToolsHelper
    {
        #region GetCountSQL
        public static string GetCountSQL(string sql)
        {
            int f1 = sql.IndexOf("From");
            if (f1 < 0)
            {
                f1 = sql.IndexOf("from");
            }
            if (f1 < 0)
            {
                f1 = sql.IndexOf("FROM");
            }
            if (f1 > 0)
            {
                sql = sql.Substring(f1);
            }
            sql = "SELECT Count(*) " + sql;
            int searchOrdery = sql.IndexOf("ORDER BY");
            if (searchOrdery >= 0)
            {
                sql = sql.Substring(0, searchOrdery - 1);
            }
            return sql;
        }

        #endregion
    }
}
